package com.wlf.admin;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.StrUtil;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class MysqlBakMain {

    public static void main(String[] args) throws IOException {

        String runShell = "C:/Users/Administrator/data/software/mysql8winx64/bin/mysqldump --skip-lock-tables --routines --add-drop-table --disable-keys --extended-insert --hex-blob -u{} -p{} --host={} --port={} {}";

        Process process = Runtime.getRuntime()
                .exec(StrUtil.format(runShell,
                        "root", // 用户名
                        "root", //  密码
                        "localhost", // 主机
                        "3306", // 端口
                        "sso_demo" //数据库
                ));
        FileUtil.writeFromStream(
                process.getInputStream(),
                FileUtil.newFile(
                        StrUtil.format("C:/Users/Administrator/Downloads/" + "back_{}.sql",
                                DateUtil.date().toString(DatePattern.PURE_DATETIME_PATTERN))));
    }

    void test(){
        String aa = "C:\\Users\\Administrator\\AppData\\Roaming\\DBeaverData\\drivers\\clients\\mysql_8\\win\\mysql.exe -u ****** --host=localhost --port=3306 sso_demo\n";
    }

}